package com.lanou.controller;

import com.alibaba.fastjson.JSON;
import com.lanou.pojo.*;
import com.lanou.service.controllerService;
import com.lanou.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "综合收银台",tags = "收银")
public class CenterController {
    @Resource
    private controllerService controllerService;

    @ApiOperation(value = "综合收银台",httpMethod = "GET")
    @RequestMapping(value = "/centerMoney",produces ="text/html;charset=utf-8")
    public String centerMessage(String resourceName){
        List<ConfigHouseEntity> paymentPayLogList = controllerService.selectControllerMessage(resourceName);
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(paymentPayLogList);
        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "综合收银台获取商铺编号",httpMethod = "GET")
    @RequestMapping(value = "/selectResourceName",produces ="text/html;charset=utf-8")
    public String selectResourceName(){
        List<String> list = controllerService.selectResourceName();
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(list);
        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "综合收银台获取项目名称",httpMethod = "GET")
    @RequestMapping(value = "/configFeeItemName",produces ="text/html;charset=utf-8")
    public String configFeeItemName(){
        List<String> list = controllerService.configFeeItemName();
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(list);
        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "综合收银台获取付款方式名称",httpMethod = "GET")
    @RequestMapping(value = "/selectPaymentContract",produces ="text/html;charset=utf-8")
    public String selectPaymentContract(String resourceName){
        List<PaymentContractEntity> list = controllerService.selectPaymentConstract(resourceName);
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(list);
        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "综合收银台获取付款方式名称",httpMethod = "GET")
    @RequestMapping(value = "/selectPaymentBill",produces ="text/html;charset=utf-8")
    public String selectPaymentBill(String resourceName){
        List<PaymentBillEntity> list = controllerService.selectPaymentBill(resourceName);
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(list);
        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "综合收银台查询历史记录列表",httpMethod = "GET")
    @RequestMapping(value = "/selectPaymentPayLog",produces ="text/html;charset=utf-8")
    public String selectPaymentPayLog(String resourceName){
        List<PaymentPayLogEntity> paymentPayLogEntities = controllerService.selectPaymentPayLog(resourceName);
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(paymentPayLogEntities);
        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "综合收银台查询临时收费列表",httpMethod = "GET")
    @RequestMapping(value = "/selectPaymentTemp",produces ="text/html;charset=utf-8")
    public String selectPaymentTemp(String resourceName){
        List<PaymentTempEntity> paymentTempEntities = controllerService.selectPaymentTemp(resourceName);
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(paymentTempEntities);
        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "综合收银台临时收费添加",httpMethod = "POST")
    @RequestMapping("/addPaymentTemp")
    public void addPaymentTemp(@RequestBody Map<String,String> datasource) throws ParseException {
        String resourceName = datasource.get("resourceName");
        String feeUser = datasource.get("feeUser");
        String feeItemName = datasource.get("feeItemName");
        String paymethod = datasource.get("paymethod");
        String money = datasource.get("money");
        String date1 = datasource.get("date1");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = dateFormat.parse(date1);
        controllerService.addPaymentTemp(resourceName,feeUser,feeItemName,paymethod,money,date);

    }

}
